
using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using aspnetcore.Models;
using aspnetcore.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace aspnetcore.Controllers
{
    public class HelloController : Controller
    {
        private readonly HSContext _dbcontext;
        private readonly ISysConfigRepository _sysConfigRepository;

        public HelloController(HSContext dbcontext, ISysConfigRepository sysConfigRepository)
        {
            _dbcontext = dbcontext;
            _sysConfigRepository = sysConfigRepository;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult welcome(string name, int numTimes = 1)
        {
            ViewData["Message"] = $"Hello {name}";
            ViewData["NumTimes"] = numTimes;

            return View();
        }

        public IActionResult Configs()
        {
            return Json(_dbcontext.SysConfig.ToList());
        }

        public async Task<IActionResult> asyncConfigs()
        {
            return Json(await _dbcontext.SysConfig.ToListAsync());
        }

        public ViewResult ConfigsPage() {

            var configs = _sysConfigRepository.getAll();

            return View(configs);
        }
    }
}
